﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Runtime.InteropServices;
using System.Linq.Expressions;
using System.Reflection;
using Project.Common;

namespace Project.Web.Base.Utility
{
	public class WebTools
	{
		/// <summary>
		/// Main页面刷新脚本
		/// </summary>
		public static string ScriptCloseDialog(DialogOption option)
		{
			var oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
			string json = oSerializer.Serialize(option);
			return string.Format("<script>window.top.closeDialog({0});</script>", json);
		}
		/// <summary>
		/// PageRightFrame页面刷新脚本
		/// </summary>
		public static string ScriptCloseEmbeddedFrameDialog(DialogOption option)
		{
			var oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
			string json = oSerializer.Serialize(option);
			return string.Format("<script>window.top.closeEmbeddedFrameDialog({0});</script>", json);

		}

		public static string ScriptRefreshDialog(int index)
		{
			return string.Format("<script>window.top.refreshDialog({0});</script>", index);
		}


		/// <summary>
		/// 判断执行类型
		/// </summary>
		/// <param name="extension"></param>
		/// <returns></returns>
		public static bool IsNotExcuteAspx(string extension)
		{
			return
				extension.Equals(".css", StringComparison.OrdinalIgnoreCase)
				|| extension.Equals(".js", StringComparison.OrdinalIgnoreCase)
				|| extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase)
				|| extension.Equals(".gif", StringComparison.OrdinalIgnoreCase)
				|| extension.Equals(".png", StringComparison.OrdinalIgnoreCase)
				|| extension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase)
				|| extension.Equals(".ico", StringComparison.OrdinalIgnoreCase)
				|| extension.Equals(".swf", StringComparison.OrdinalIgnoreCase)
				;
		}

	}

	public class DialogOption
	{

		private DialogOption()
		{

		}

		public static DialogOption GetDefaultInstance()
		{
			return new DialogOption()
			{
				Index = 1,
				IsRefreshParent = true,
				IsRefreshParentAsynchronous = true,
				IsShowMessage = true,
				Message = "操作成功",
				Form = "form"
			};
		}

		public int Index
		{
			get;
			set;
		}

		public int Width
		{
			get;
			set;
		}

		public int Height
		{
			get;
			set;
		}

		public bool IsRefreshParent
		{
			get;
			set;
		}

		public bool IsRefreshParentAsynchronous
		{
			get;
			set;
		}

		public bool IsShowMessage
		{
			get;
			set;
		}

		public string Callback
		{
			get;
			set;
		}

		public string Message
		{
			get;
			set;
		}

		public string Form
		{
			get;
			set;
		}
	}
}